﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Medicine.Util;
using System.Data;
namespace Medicine.Dao
{
    class RecordDao
    {

        public void insertRecord(String sql) {

            DbHelper.insert(sql);
        }
        /// <summary>
        /// 获取用户的购买记录
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public List<Dictionary<String, Object>> queryUserRecord(String sql)
        {
            List<Dictionary<String, Object>> med_list = new List<Dictionary<String, Object>>();
            DataSet ds = DbHelper.query(sql);
            DataTable dt = ds.Tables[0];
            // MessageBox.Show(dt.Rows.Count.ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                Dictionary<String, Object> medicine = new Dictionary<String, Object>();
                medicine.Add("name", dt.Rows[i][0]);
                medicine.Add("price", dt.Rows[i][1]);
                medicine.Add("info", dt.Rows[i][2]);
                medicine.Add("address", dt.Rows[i][3]);
                medicine.Add("remark", dt.Rows[i][4]);
                medicine.Add("time", dt.Rows[i][5]);
                med_list.Add(medicine);
            }
            return med_list;
        }
        /// <summary>
        /// 获取交易记录
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns></returns>
        public List<Dictionary<String, Object>> queryUserRecord1(String sql)
        {
            List<Dictionary<String, Object>> med_list = new List<Dictionary<String, Object>>();
            DataSet ds = DbHelper.query(sql);
            DataTable dt = ds.Tables[0];
            // MessageBox.Show(dt.Rows.Count.ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                Dictionary<String, Object> medicine = new Dictionary<String, Object>();
                medicine.Add("name", dt.Rows[i][0]);
                medicine.Add("price", dt.Rows[i][1]);
                medicine.Add("info", dt.Rows[i][2]);
                medicine.Add("id", dt.Rows[i][3]);
                medicine.Add("use_id", dt.Rows[i][4]);
                medicine.Add("address", dt.Rows[i][5]);
                medicine.Add("remark", dt.Rows[i][6]);
                medicine.Add("time", dt.Rows[i][7]);
                med_list.Add(medicine);
            }
            return med_list;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">编号</param>
        public void delete(int id)
        {
            String sql = "delete from record where id='" + id + "'";
            DbHelper.insert(sql);
        }
    }
}
